package com.hnyfkj.jyindustry.biz.parameter.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.hnyfkj.jyindustry.biz.parameter.dto.ParameterDto;
import com.hnyfkj.jyindustry.biz.parameter.dto.ParameterInsertDto;
import com.hnyfkj.jyindustry.biz.parameter.dto.ParameterQueryDto;
import com.hnyfkj.jyindustry.biz.parameter.dto.ParameterReturn;
import com.hnyfkj.jyindustry.biz.parameter.dto.ParameterTypeDto;
import com.hnyfkj.jyindustry.biz.parameter.dto.ParameterUpdateDto;
import com.hnyfkj.jyindustry.biz.parameter.entity.ParameterEntity;
import com.hnyfkj.jyindustry.biz.parameter.service.ParameterService;
import com.hnyfkj.jyindustry.common.utils.PageUtils;
import com.hnyfkj.jyindustry.common.utils.Response;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * @author zjq
 * @Description
 * @date 2020年12月21日
 */
@Controller
@RequestMapping("parameter")
@Api(tags = {"参数信息"})
public class ParameterController {

	@Autowired
	private ParameterService parameterService;

	/**
	 * 添加页面
	 */
	@GetMapping("/add")
	public String addPage() {
		return "parameter/parameter-add";
	}

	/**
	 * 编辑页面
	 */
	@GetMapping("/edit")
	public String editPage(@RequestParam("id") String id, Model model) {
		ParameterEntity parameterEntity = parameterService.getById(id);
		model.addAttribute("parameterEntity", parameterEntity);
		return "parameter/parameter-edit";
	}

	/**
	 * 列表页面
	 */
	@GetMapping("/listPage")
	public String listPage() {
		return "parameter/parameter-table";
	}

	/**
	 * 参数类型列表页面
	 */
	@GetMapping("/typeListPage")
	public String typeListPage() {
		return "parameter/parameter-type-table";
	}

	/**
	 * 查询参数类型列表
	 */
	@PostMapping("/getParameterType")
	@ResponseBody
	@ApiOperation(value = "查询参数类型列表", produces = "application/json")
	public Response<List<ParameterTypeDto>> getParameterType(@RequestBody final ParameterTypeDto parameterTypeDto) {
		List<ParameterTypeDto> list = parameterService.getParameterType(parameterTypeDto);
		return Response.success(list.size(), list);
	}

	/**
	 * 查询参数
	 */
	@PostMapping("/getParameter")
	@ResponseBody
	@ApiOperation(value = "查询参数", produces = "application/json")
	public Response getParameter(@RequestBody final ParameterDto parameterDto) {
		List<ParameterDto> list = parameterService.getParameter(parameterDto);
		return Response.success(list.size(), list);
	}

	/**
	 * 新增参数
	 */
	@PostMapping("/save")
	@ResponseBody
	@ApiOperation(value = "新增参数", produces = "application/json")
	public Response save(@RequestBody final ParameterInsertDto parameterInsertDto) {
		parameterService.insert(parameterInsertDto);
		return Response.success();
	}

	/**
	 * 修改参数
	 */
	@PostMapping("/update")
	@ResponseBody
	@ApiOperation(value = "修改参数", produces = "application/json")
	public Response update(@RequestBody final ParameterUpdateDto parameterUpdateDto) {
		parameterService.update(parameterUpdateDto);
		return Response.success();
	}

	/**
	 * 删除
	 */
	@PostMapping("/delete")
	@ResponseBody
	@ApiOperation(value = "删除")
	public Response delete(@RequestParam("ids[]") final String[] ids) {
		parameterService.delectBatch(ids);
		return Response.success();
	}

	/**
	 * @author wangf
	 * <p>
	 * 说明: 参数列表查询
	 * @date 2020/12/30 14:40
	 */
	@PostMapping("/selectListDto")
	@ResponseBody
	@ApiOperation(value = "参数列表查询 分页", produces = "application/json")
	public Response<PageUtils<ParameterReturn>> selectListDto(@RequestBody final ParameterQueryDto queryDto) {
		PageUtils<ParameterReturn> ls = parameterService.selectListDto(queryDto);
		return Response.success(ls.getCount(), ls.getList());
	}
}
